package Test;

import java.util.Date;

import junit.framework.TestCase;

import org.junit.Test;

import business.Schedule;
import data.Job;

/**
 * Test class for the Schedule class
 * @author Faiz
 * @version 2/23/2011
 */
public class ScheduleTest extends TestCase {

	/**
	 * author Minh
	 * 
	 * This test add addJob() method
	 * 1) Add Job that has been verified
	 * 2) Add Job that has not been verified
	 */
	@Test
	public void testAddJob() {
		Schedule theSchedule = new Schedule();
		//1)
		Job j = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		j.setVerified(true);
		theSchedule.addJob(j);
		assertTrue(theSchedule.viewScheduledJob().contains(j));
		assertFalse(theSchedule.viewUnscheduledJob().contains(j));
		//2)
		Job k = new Job("Test2", "555-6666", "Test unds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		k.setVerified(false);
		theSchedule.addJob(k);
		assertFalse(theSchedule.viewScheduledJob().contains(k));
		assertTrue(theSchedule.viewUnscheduledJob().contains(k));		
	}
	
	
	/**
	 * Tests the constructor for the schedule
	 * class. Test to make sure that the object
	 * and its vital fields are initialized after
	 * construction.
	 */
	@Test
	public void testSchedule() {
		Schedule test = new Schedule();
		assertTrue(test != null);
		assertTrue(test.viewScheduledJob() != null);
		assertTrue(test.viewUnscheduledJob() != null);
	}

	/**
	 * Tests that a scheduledjob is added to the list of scheduled
	 * jobs and that an unscheduled job is not for both types of
	 * job constructors.
	 */
	@Test
	public void testAddScheduledJob() {
		Schedule test = new Schedule();
		Job unverified = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test.addJob(unverified);
		assertFalse(test.viewScheduledJob().contains(unverified));
		
		Job verified = new Job("Test2", "555-6666", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		verified.setVerified(true);
		test.addJob(verified);
		assertTrue(test.viewScheduledJob().contains(verified));
	}

	/**
	 * Tests to make sure a scheduled job is added to the scheduled
	 * job list and an unscheduled job is not. 
	 */
	@Test
	public void testAddUnscheduledJob() {
		Schedule test = new Schedule();
		Job unverified = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test.addJob(unverified);
		assertTrue(test.viewUnscheduledJob().contains(unverified));
		
		Job verified = new Job("Test2", "555-6666", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		verified.setVerified(true);
		test.addJob(verified);
		assertFalse(test.viewUnscheduledJob().contains(verified));
	}

	/**
	 * Tests to make sure an unscheduled job that is
	 * added can be removed. And that removing a job that
	 * doesnt exist does not crash the system.
	 */
	@Test
	public void testRemoveUnscheduledJob() {
		Schedule test = new Schedule();
		Job unverified = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test.addJob(unverified);
		assertTrue(test.viewUnscheduledJob().contains(unverified));
		test.removeUnscheduledJob(unverified);
		assertFalse(test.viewUnscheduledJob().contains(unverified));
		
		Job unverfied2 = new Job("Test2", "555-6666", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test.removeUnscheduledJob(unverfied2);
	}

	/**
	 * Tests to make sure that unscheduled jobs are added
	 * to the unscheduled jobs list and can be viewed
	 */
	@Test
	public void testViewUnscheduledJob() {
		Schedule test = new Schedule();
		assertTrue(test.viewUnscheduledJob() != null);
		Job unverified = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);;
		test.addJob(unverified);
		assertTrue(test.viewUnscheduledJob().get(0).equals(
				new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9)));

	}

	/**
	 * Test to see if scheduled jobs can be added and viewed
	 * from the scheduled job list.
	 */
	@Test
	public void testViewScheduledJob() {
		Schedule test = new Schedule();
		Job verified = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		verified.setVerified(true);
		test.addJob(verified);
		assertTrue(test.viewScheduledJob().get(0).equals(verified));
	}
	
	/**
	 * Tests the toString() method of the Schedule class.
	 * 
	 * author Stephen Amos
	 */
	@Test
	public void testToString() {
		Schedule test = new Schedule();
		Job test_job = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test.addJob(test_job);
		assertEquals(test.toString(), test_job.toString());
	}
}
